<template>
  <div class="set-admin-ecs">
    <w-nav-bar
      title="ECS"/>
    <w-cell
      v-for="(v) in files"
      :key="v.filePath"
      :icon="v.filePath"
      :header="v.name"
      @click="deleteBtnClick(v)"/>
    <w-empty-data ref="WEmptyData"/>
    <w-bottom-btn
      btn1-title="删除所有"
      btn2-title=""
      :dispose1="false"
      dispose-parameter1="title"
      @click1="removeAllBtnClick"/>
  </div>
</template>

<script>
  import WCell from '@/components/mobile/cell'
  import ECSFileModel from '@/models/ecs/ECSFileModel'
  import WBottomBtn from '@/components/mobile/confirmBottomBtn'
  import WEmptyData from '@/components/global/empty'
  export default {
    name: "SetAdminEcs",
    components: {
      WCell,
      WBottomBtn,
      WEmptyData
    },
    data() {
      return {
        /**
         * 文件列表
         */
        files: []
      }
    },
    mounted() {
      this.getAllFile()
    },
    methods: {
      /**
       * 获取所有文件
       */
      getAllFile() {
        ECSFileModel.loadAllModels().w_then((dataArr) => {
          this.files = dataArr
          this.$refs['WEmptyData'].show(dataArr)
        })
      },
      /**
       * 删除按钮点击
       * @param index
       * @param item
       */
      deleteBtnClick(item) {
        item.remove('name').w_then(() => {
          this.getAllFile()
        })
      },
      /**
       * 删除所有数据
       */
      removeAllBtnClick() {
        this.$w_remove_pop(() => {
          return ECSFileModel.removeAll()
        }, '所有数据').w_then(() => {
          this.getAllFile()
        })
      }
    }
  }
</script>

<style lang="scss" scoped>

</style>
